import json from 'rollup-plugin-json'
import resolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import babel from 'rollup-plugin-babel'
import { terser } from 'rollup-plugin-terser'
import typescript from 'rollup-plugin-typescript2'

const NODE_ENV = process.env.NODE_ENV

const config = {
  input: 'src/index.ts',
  output: {
    dir: 'dist',
    format: 'umd',
    name: 'bundle',
    globals: {
      jsencrypt: 'jsencrypt'
    }
  },
  external: ['jsencrypt'],
  plugins: [
    resolve(),
    babel({
      exclude: 'node_modules/**' // 仅仅转译我们的源码
    }),
    json(),
    commonjs(),
    typescript({
      tsconfig: 'tsconfig.json'
    }),
  ]
}

if (NODE_ENV === 'production') {
  config.plugins.push(terser())
}

export default config